import 'package:seedfour/app/models/dictionary_entity.dart';
import 'package:seedfour/app/models/invite_user_entity.dart';
import 'package:seedfour/app/models/org_name_entity.dart';
import 'package:seedfour/app/models/transfer_user_entity.dart';
import 'package:seedfour/generated/json/base/json_convert_content.dart';
import 'package:seedfour/app/models/api_response/list_data_entity.dart';

ListDataEntity<T> $ListDataEntityFromJson<T>(Map<String, dynamic> json) {
  final ListDataEntity<T> listDataEntity = ListDataEntity<T>();

  final List<T>? records = jsonConvert.convertListNotNull<T>(json['data']);
  if (records != null) {
    listDataEntity.data = records;
  }

  return listDataEntity;
}

Map<String, dynamic> $ListDataEntityToJson(ListDataEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['data'] = entity.data;
  return data;
}

M? listDataFromJsonSingle<M>(Map<String, dynamic> json) {
  String type = M.toString();
  String genericType = type.substring(type.indexOf("<") + 1, type.length - 1);
  if ((TransferUserEntity).toString() == genericType) {
    final pagingData = ListDataEntity<TransferUserEntity>.fromJson(json);
    return pagingData as M;
  } else if ((DictionaryEntity).toString() == genericType) {
    final pagingData = ListDataEntity<DictionaryEntity>.fromJson(json);
    return pagingData as M;
  } else if ((InviteUserEntity).toString() == genericType) {
    final pagingData = ListDataEntity<InviteUserEntity>.fromJson(json);
    return pagingData as M;
  } else if ((OrgNameEntity).toString() == genericType) {
    final pagingData = ListDataEntity<OrgNameEntity>.fromJson(json);
    return pagingData as M;
  }

  return ListDataEntity<TransferUserEntity>.fromJson(json) as M;
}
